import  axios from 'axios'

import cookies from 'js-cookie'
export default function({req,res}) {

if (req&&req.headers &&req.headers.cookie) {

    let cookieArr = req.headers.cookie;
    const getCity = getCookie('city', cookieArr)
    //设置axios的全局变量.
    axios.defaults.timeout = 60000 // 响应时间
    // @requestParams
    axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
    axios.defaults.headers.city = getCity
    axios.defaults.withCredentials = true

  }
}
function getCookie (name, strCookie) {
 
    // console.log('strCookie',strCookie)
   
    var arrCookie = strCookie.split(';')
   
    for (var i = 0; i < arrCookie.length; i++) {
   
      var arr = arrCookie[i].split('=')
   
      if (arr[0].trim() === name) {
   
        return arr[1]
   
      }
   
    }
   
    return {}
   
  }